<?php

/**
 * 用于接收客户端发送的心跳
 * @authors Hex (hex@zpdchina.com)
 * @date    2017-03-09 11:09:02
 * @version $Id$
 */
class HeartbeatController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $request = $this->getRequest();
        $yiyuan_id = $request->getPost('yiyuan_id',0);
        $session_key = $request->getPost('session_id','');
//        if(empty($yiyuan_id))
//            Utility::apiJsonError(30001, '医院编号不能为空');
        if(empty($session_key))
            Utility::apiJsonError(30020, 'Sesskey不能为空');
        $now = time();//失效时间
        $sess_mdl = new YiyuanSessModel;
        //获取sess信息
        $sess = $sess_mdl->getSess($session_key,$now);
        if (empty($sess)) {// session为空
            $async_result["state"] = "session_time_out";
        } else {
            // session不为空，更新session信息
            $expirytime = $now + 180;
            $sess_mdl->updateSess($sess['id'],$expirytime);
            $async_result["state"] = "ok";
            //增加返回登陆状态接口
            $async_result["login_state"] = $sess['login_state'];
        }
        $async_result['error'] = 200;
        $async_result['msg'] = "";
        Utility::apiJsonResultExtends($async_result);
    }
}